using UnityEngine;

namespace CinemaDirector
{
	[CutsceneItem("Tween", "Fill")]
	public class GGTweenFill : CinemaGlobalAction
	{
		public UISprite widget;

		public float from;

		public float to;

		public Interpolate.EaseType easeType;

		protected float cachedFill;

		public void SetProperty(float fill)
		{
			widget.fillAmount = fill;
		}

		public virtual float GetProperty()
		{
			return widget.fillAmount;
		}

		public override void Trigger()
		{
			SetProperty(from);
		}

		public override void Initialize()
		{
			cachedFill = GetProperty();
		}

		public override void Stop()
		{
			if (!Application.isPlaying)
			{
				SetProperty(cachedFill);
			}
		}

		public override void ReverseTrigger()
		{
			End();
		}

		public override void End()
		{
			SetProperty(to);
		}

		public override void ReverseEnd()
		{
			Trigger();
		}

		public override void UpdateTime(float time, float deltaTime)
		{
			Interpolate.Function function = Interpolate.Ease(easeType);
			SetProperty(function(from, to - from, time, Mathf.Max(0.01f, base.Duration)));
		}

		public override void SetTime(float time, float deltaTime)
		{
			if (!(time < 0f) && !(time > base.Duration))
			{
				UpdateTime(time, deltaTime);
			}
		}
	}
}
